<?php
session_start();
$user = $_SESSION['user'];



?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="shortcut icon" href="ico/logo.ico" type="image/x-icon" />
    <title>协同办公-邮箱</title>
    <link rel="stylesheet" href="../static/css/bootstrap.css">
    <link rel="stylesheet" href="../static/js/layui/css/layui.css">
    <link rel="stylesheet" href="../static/css/font.css">
    <style>
        #boxes{
            width: 98%;
            margin: auto;
            display: flex;
            flex-direction: row;

        }
        #boxes>div{
            margin-left: 5%;
        }
        #left>a{
            margin-top:30px;
           margin-left: 20px;
            cursor: pointer;
        }
        #logo{
            margin-top: 20px;
            margin-left: 6%;
            height: 80px;
            display: flex;
            flex-direction: row;
        }
        #tiao{
            width: 100%;
            height: 50px;
            background-image: url("../static/imaegs/breadbg.gif");
            display: flex;
            flex-direction: row;
        }
        #right{
            margin-top: 10px;
            margin-left: 30%;

        }
        #from_block{
            width: 80%;
            margin-left: 10%;
            height: 300px;

        }
        #left{
            margin-left: 10%;
            margin-top: 10px;
        }
#user{
    background-color: transparent;
    border: hidden;
    width:150px;

}
        #logo-img{
            width:150px;
            height: 93px;
        }
        #logo-img>img{
            width: 90%;
        }
        #logo-right{
            width: 300px;
            height: 50px;
            margin-left:50%;
        }
        #time{
            float: right;
            margin-right: 50px;
            font-size: 9px;
        }
        #overTime{
            color: crimson;
            font-size: 9px;
            float: right;
            margin-right: 5px;
        }
        #file{
            margin-right: 10px;
            margin-top: 8px;
            float: right;
        }
        #title-form{
            width: 120px;
        }
        #logo-img{
            width:150px;
            height: 93px;
        }
        #logo-img>img{
            width: 90%;
        }
        #logo-right{
            width: 300px;
            height: 50px;
            margin-left:50%;
        }

        label{
            margin-left: 5px;
            font-size: 9px;

        }


        #title-form{
            width: 120px;
        }
#passDiv{
    display: none;
}
    </style>
</head>
<body>
<div id="logo"><div id="logo-img"><img src="../static/imaegs/logo/logo2.png"></div>
<div id="logo-right">
    <h5 ><i class="layui-icon" style="font-size: 18px; color: orange">&#xe645;</i>&nbsp;最新公告：<span id="notice">暂无公告</span></h5>
</div>
</div>
<div id="tiao">
    <div id="left"><a href="index.php"><i class="layui-icon" style="font-size: 20px; color: #1E9FFF;">&#xe68e;</i>&nbsp;首页</a>
        <a href="task.php"> <i class="layui-icon" style="font-size: 20px; color: #1E9FFF;">&#xe6b2;</i>&nbsp;任务</a>
        <a href="notice/notice.php"> <i class="layui-icon" style="font-size: 20px; color: #1E9FFF;">&#xe637;</i>&nbsp;公告栏</a>
        <a href="file.php"><i class="layui-icon" style="font-size: 20px; color: #1E9FFF;">&#xe621;</i>&nbsp;文件管理</a>
        <a href="add_user.php"><i class="layui-icon" style="font-size: 20px; color: #1E9FFF;">&#xe613;</i>&nbsp;用户管理</a></div>
    <div id="right"><a style="color:grey" href="index.php">您好！&nbsp;<i class="layui-icon" style="font-size: 20px; color: #1E9FFF;">&#xe66f;</i><input id="user" name="user" readonly="readonly" value="<?php echo $user ?>"></a><a href="login.html">退出</a></div>
</div>

<div id="from_block">


    <div class="layui-tab-item layui-show">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-header" id="message">修改个人信息</div>
                    <div class="layui-card-body" style="display: flex;flex-direction: row">
                        <div id="from-left">
                            <div class="layui-form-item">

                                <label class="layui-form-label login-form" id="title-form"><i class="iconfont" style="color: #0b3b8c">&#xe6b8;</i>账号：</label>
                                <div class="layui-input-inline login-inline">
                                    <input type="text" name="userA" id="userA" lay-verify="required" placeholder="请输入用户的帐号" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <input type="text" style="display: none" name="id" id="id" >
                            <input type="text" style="display: none"  name="img-url" id="img-url" >
                            <div class="layui-form-item">
                                <label class="layui-form-label login-form" id="title-form"><i class="iconfont" style="color: #0b3b8c">&#xe6b8;</i>邀请码：</label>
                                <div class="layui-input-inline login-inline">
                                    <input type="text" name="code" id="code" lay-verify="required" placeholder="请编写邀请码" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label login-form" id="title-form" ><i class="iconfont" style="color: #0b3b8c">&#xe6b2;</i>团队名称：</label>
                                <div class="layui-input-inline login-inline">
                                    <input type="text" name="classA" id="classA"  lay-verify="required"  placeholder="小组名称" autocomplete="off" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-card-header">修改密码 :&nbsp;&nbsp;  <button class="layui-btn layui-btn-primary layui-btn-sm" onclick="passBox()"><i class="layui-icon"></i></button></div>
                            <div class="layui-form-item" id="passDiv">
                                <label class="layui-form-label login-form" id="title-form"><i class="iconfont" style="color: #0b3b8c">&#xe6b2;</i>密码：</label>
                                <div class="layui-input-inline login-inline">
                                    <input type="password" name="passA" id="passA" autocomplete="off"  lay-verify="required"  class="layui-input">
                                </div>
                                <div class="layui-input-inline login-inline"style="display: none">
                                    <input type="password" name="pass" id="pass" autocomplete="off"  lay-verify="required"  class="layui-input">
                                </div>
                            </div>

                            <div class="layui-card-header">头像设置</div>
                            <div class="layui-input-block">

                                <form action="" enctype="multipart/form-data" method="">
                                    <a class="opts_btn" href="JavaScript:void(0)">
                                        <input  name="myFile" class="oFile" id="oFile"  onchange="FileChangeFn(event)" type="file">
                                    </a>
                                    <label id="file_size"></label><br><br>
                                    <div id="file_box"></div>
                                    <div class="speed_box">
                                        <div id="speed">0%</div>
                                    </div>
                                    <label id="file_type"></label>
                                    <button class="layui-btn" onclick="UploadFileFn()" type="button">开始上传文件</button>
                                    <div class="clear"></div> <input style="display: none" class="hui-input" id="url" name="url"  type="text">
                                </form>

                            </div>
                        </div>
                        <div id="from-right" style="margin-left: 100px">


                            <div class="layui-form-item">
                                <label class="layui-form-label login-form" id="title-form"><i class="iconfont" style="color: #0b3b8c">&#xe6b2;</i>邮箱：</label>
                                <div class="layui-input-inline login-inline">
                                    <input type="email" name="email" id="email"  lay-verify="required" placeholder="邮箱" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label login-form" id="title-form"><i class="iconfont" style="color: #0b3b8c">&#xe6b2;</i>电话：</label>
                                <div class="layui-input-inline login-inline">
                                    <input type="text" name="tel" id="tel"  lay-verify="required" placeholder="电话" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <hr>

                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>
<hr>
    <button class="btn btn-warning " lay-submit lay-filter="login" style="float: right" onclick="update()" type="button">确认修改</button>
</div>
<hr>



<ins class="adsbygoogle" style="display:inline-block;width:970px;height:90px" data-ad-slot="3820120620" data-ad-client="ca-pub-6111334333458862"></ins>
<div id="boxes">
    <a style="font-size: 9px">
    版权信息：xianghai保留所有权利，请尊重他人的劳动成果

    </a>
</div>
<script src="../static/js/jquery.min.js"></script>
<script src="../static/js/layui/layui.all.js"></script>
<script>


    if($('#user').val()===""){
        layer.msg("您还没有登陆哦！");
        window.location.href="login.html";

    }
  function passBox() {
      var passDiv=document.getElementById("passDiv");
      passDiv.style.display="block";
  }
    var uploadUrl = '../php/user/upload.php';
    //文件选择完毕时
    function FileChangeFn(event) {
        $('.opst_txt').text('重新选择文件');
        $('.send_btn').show();
        var event = event || window.event,
            dom = '',
            ofile = $("#oFile").get(0).files[0],
            otype = ofile.type || '获取失败',
            osize = ofile.size / 1054000,
            ourl = window.URL.createObjectURL(ofile); //文件临时地址
        $('#file_type').text("选择上传文件类型：" + otype);
        $('#file_size').text("选择上传文件大小，共" + osize.toFixed(2) + "MB。");

        console.log("文件类型：" + otype); //文件类型
        console.log("文件大小：" + osize); //文件大小

        if ('video/mp4' == otype || 'video/avi' == otype || 'video/x-msvideo' == otype) {
            layer.msg("请上传压缩文件/或者图片");
        }
        if ('audio/mp3' == otype || 'audio/wav' == otype  || 'audio/x-m4a' == otype) {
            layer.msg("请上传压缩文件/或者图片");
        }
        if ('image/jpeg' == otype || 'image/png' == otype || 'image/gif' == otype) {
            dom = '<img id="photo" width="100%"  alt="我是image图片文件" src=' + ourl + ' title="" />';
        }
        if ('zip' == otype) {
            dom = '<img id="photo" width="100%"  alt="我是压缩文件" src=' + ourl + ' title="" />';
        }
        $('#file_box').html(dom);
    };

    //侦查附件上传情况 ,这个方法大概0.05-0.1秒执行一次
    function OnProgRess(event) {
        var event = event || window.event;
        //console.log(event);  //事件对象
        console.log("已经上传：" + event.loaded); //已经上传大小情况(已上传大小，上传完毕后就 等于 附件总大小)
        //console.log(event.total);  //附件总大小(固定不变)
        var loaded = Math.floor(100 * (event.loaded / event.total)); //已经上传的百分比
        $("#speed").html(loaded + "%").css("width", loaded + "%");
    };

    //开始上传文件
    function UploadFileFn() {


        var file=document.getElementById("oFile");
        fileV=file.value;
        if(fileV===""){
            layer.msg("您还没有选择任何文件哦")
        }
        else {

            $('.speed_box').show();
            var oFile = $("#oFile").get(0).files[0], //input file标签
                formData = new FormData(); //创建FormData对象
            xhr = $.ajaxSettings.xhr(); //创建并返回XMLHttpRequest对象的回调函数(jQuery中$.ajax中的方法)
            formData.append("myFile", oFile); //将上传name属性名(注意：一定要和 file元素中的name名相同)，和file元素追加到FormData对象中去

            $.ajax({
                type: "POST",
                url: uploadUrl, // 后端服务器上传地址
                data: formData, // formData数据
                cache: false, // 是否缓存
                async: true, // 是否异步执行
                processData: false, // 是否处理发送的数据  (必须false才会避开jQuery对 formdata 的默认处理)
                contentType: false, // 是否设置Content-Type请求头
                dataType: 'json',
                xhr: function () {
                    if (OnProgRess && xhr.upload) {
                        xhr.upload.addEventListener("progress", OnProgRess, false);
                        return xhr;
                    }
                },
                success: function (dat) {

                    $("#speed").html("上传成功");
                    var url=document.getElementById("img-url");
                    url.value=dat.src;
                },
                error: function (dat) {
                    $("#speed").html("上传失败");

                    layer.msg('请正确配置后台服务！');
                }
            });
        }
    }

    $.ajax({
        type: 'post',
        cache: false,
        url: '../php/admin/select_notice.php',
        data: {
        },
        dataType: 'json',
        success: function (data) {
            $dat = data.data
            $coun = data.count;
            $notice=$dat[0].content;
            var not=document.getElementById("notice");
            not.innerHTML=$notice;
        },
        error: function (data) {

        }
    });
//获取管理员的信息
    var user=document.getElementById("user").value;
    $.ajax({
        type: 'post',
        cache: 'false',
        url: '../php/admin/select_admin.php',
        data: {
            "user":user,
        },
        dataType: 'Json',
        success: function (dat) {
            var user_name=document.getElementById("userA"),
                user_tel=document.getElementById("tel"),
                user_email=document.getElementById("email"),
                user_class=document.getElementById("classA"),
                code=document.getElementById("code"),
            url=document.getElementById("img-url"),
            id=document.getElementById("id");

            $dat=dat.data[0];
            user_class.value=$dat.className;
            user_tel.value=$dat.tel;
            user_email.value=$dat.email;
            user_name.value=$dat.user;
            code.value=$dat.code;
            url.value=$dat.img;
            id.value=$dat.id;
        },
        error: function (dat) {
            layer.msg("请检查网络是否正常");
        }


    })

    function update() {
        $id=$('#id').val();
        $user=$('#userA').val();
        $class=$('#classA').val();
        $tel=$('#tel').val();
        $url=$('#img-url').val();
        $email=$('#email').val();
        $pass=$('#passA').val();
        $code=$("#code").val();


        $.ajax({
            type:'post',
            cache:'false',
            url:'../php/admin/admin_update.php',
            data:{
                "id":$id,
                "user":$user,
                "class":$class,
                "tel":$tel,
                "email":$email,
                "url":$url,
                "code":$code,
                "pass":$pass,
            },
            dataType:'json',
            success:function (dat) {
                layer.msg(dat.message);

            },
            error:function (dat) {
                layer.msg("修改失败");
            }



        });


    }
</script>

</body>
</html>